# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_realname=fastapi
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.115.12
pkgrel=1
pkgdesc='FastAPI framework, high performance, easy to learn, fast to code, ready for production (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/tiangolo/fastapi'
msys2_references=(
  'purl: pkg:pypi/fastapi'
  "cpe: cpe:2.3:a:fastapi_project:fastapi"
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-anyio" # implicitly required for concurrency
         "${MINGW_PACKAGE_PREFIX}-python-pydantic"
         "${MINGW_PACKAGE_PREFIX}-python-starlette")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-pdm-backend")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-email-validator: for email validation"
            "${MINGW_PACKAGE_PREFIX}-python-itsdangerous: for SessionMiddleware support"
            "${MINGW_PACKAGE_PREFIX}-python-jinja: for default starlette template configuration"
            "${MINGW_PACKAGE_PREFIX}-python-pyyaml: for starlette SchemaGenerator support"
            "${MINGW_PACKAGE_PREFIX}-python-ujson: for faster JSON parsing and UJSONResponse"
            "${MINGW_PACKAGE_PREFIX}-python-websockets: for WebSockets support"
            "${MINGW_PACKAGE_PREFIX}-uvicorn: for Uvicorn as ASGI server")
options=('!strip')
source=("${url}/archive/${pkgver}${_realname}-$pkgver.tar.gz")
sha256sums=('a333ccfd85b9abdcc94fd278fcd397c85c4007f881810fbc0fc713a04c5f2004')

prepare() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    "${MINGW_PREFIX}"/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
